#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int Maxn=1e6+7;
const int Mod=1e9+7;
const ll inf=1e16;
int n,k;
ll a[Maxn];
ll bas=1,f[Maxn],suf[Maxn];

struct TREE{
	int l,r;
	ll val;
}tree[Maxn<<2];
void buildtree(int node,int l,int r){
	tree[node].l=l,tree[node].r=r;
	if(l==r){
		tree[node].val=inf;
		return ;
	}
	int mid=tree[node].l+tree[node].r>>1;
	buildtree(node<<1,l,mid);
	buildtree(node<<1|1,mid+1,r);
}
inline void pushup(int node){
	tree[node].val=min(tree[node<<1].val,tree[node<<1|1].val);
}
void modify(int node,int x,ll k){
	if(tree[node].l==tree[node].r){
		tree[node].val=k;
		return ;
	}
	int mid=tree[node].l+tree[node].r>>1;
	if(x<=mid) modify(node<<1,x,k);
	else modify(node<<1|1,x,k);
	pushup(node);
}
ll query(int node,int l,int r){
	
	if(tree[node].l>=l and tree[node].r<=r) return tree[node].val;
	int mid=tree[node].l+tree[node].r>>1;ll ret=inf;
//	cout<<tree[node].l<<" "<<tree[node].r<<" "<<mid<<" "<<l<<" "<<r<<endl;
	if(l<=mid) ret=min(ret,query(node<<1,l,r));
	if(r>mid) ret=min(ret,query(node<<1|1,l,r));
	return ret;
}

int main(){
	freopen("knight.in","r",stdin);
	freopen("knight.out","w",stdout);

	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]),f[i]=inf;
	
	if(n<=4000){
		
		for(int i=1;i<=n;i++){
			suf[i+1]=-inf;
			for(int j=i;j>=max(0,i-k);j--) suf[j]=max(suf[j+1],a[j]); 
			
			for(int j=1;j<=min(i,k);j++){
				f[i]=min(f[i],f[i-j]+suf[i-j+1]);
			}
		}
		ll ans=0;
		for(int i=n;i;i--){
//			cout<<f[i]<<" ";
			ans=(ans+(f[i]%Mod)*bas%Mod)%Mod;
			bas=bas*23%Mod;
		}
		printf("%lld",ans);
		return 0;
	} 
	
	buildtree(1,1,n);
	ll mn=0;
	for(int i=1;i<=k;i++){
		mn=max(mn,a[i]);
		f[i]=mn;
		modify(1,i,f[i]);
	}
	
	for(int i=k+1;i<=n;i++){
		f[i]=query(1,i-k,i-1)+a[i];
		modify(1,i,f[i]);
	}
	ll ans=0;
	for(int i=n;i;i--){
		ans=(ans+(f[i]%Mod)*bas%Mod)%Mod;
		bas=bas*23%Mod;
	}
	printf("%lld",ans);
	
	
	return 0;
}
/*
6 3
3 4 1 5 6 8

13 3
1 2 3 4 5 5 6 8 8 8 10 10 13

10 4
9 1 7 15 13 11 7 4 3 12

*/

